﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BL;
using DA;
namespace QL_KhachHang
{
    public partial class FrmChucvu : Form
    {
        public FrmChucvu()
        {
            InitializeComponent();
        }
        ChucVu_BL cv = new ChucVu_BL();
        private void FrmChucvu_Load(object sender, EventArgs e)
        {
            cbmacv.DataSource = cv.LayDSCV();
            cbmacv.DisplayMember = "MaCV";
            hienthi();
        }

        private void hienthi()
        {
            listView1.Items.Clear();
            foreach (var item in cv.LayDSCV())
            {
                ListViewItem it = new ListViewItem(item.MaCV);
                it.SubItems.Add(item.TenCV);
                it.SubItems.Add(item.Luong.ToString());
                listView1.Items.Add(it);
            }
        }

        private void cbmacv_SelectedIndexChanged(object sender, EventArgs e)
        {
            txttencv.Text = cv.LayTenCVTheoMaCV(cbmacv.Text);
        }

        private void btsua_Click(object sender, EventArgs e)
        {
            ChucVu c = new ChucVu();
            c.MaCV = cbmacv.Text;
            c.Luong =double.Parse(txtluong.Text);
            if (cv.suacv(c)==true)
            {
                MessageBox.Show("Sửa thành công");
                hienthi();
            }
            else
            {
                MessageBox.Show("Lỗi!!!");
            }
        }
        bool ktso;
        private void txtluong_KeyDown(object sender, KeyEventArgs e)
        {
            ktso = true;
            if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)

                if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)

                    if (e.KeyCode != Keys.Back)

                        ktso = false;
        }

        private void txtluong_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!ktso)
            {
                e.Handled = true;
                MessageBox.Show("Lương phải là số");
            }
        }

        private void listView1_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                cbmacv.Text = listView1.FocusedItem.SubItems[0].Text;
                txtluong.Text = listView1.FocusedItem.SubItems[2].Text;
            }
            catch 
            {
            }
        }
    }
}
